import {debounce} from "./utilis";
import BackTop from "@/components/common/backTop/BackTop";
import PubSub from "pubsub-js";

//监听图片加载的防抖函数
export const imgLoadMixin = {
  data(){
    return {
      imgLoadListener:null
    }
  },
  mounted() {
    let refresh = debounce(this.$refs.scroll.refresh, 200)
    this.imgLoadListener = () => {
      refresh()
    }
    // 图片加载让scroll重新计算滑动高度
    PubSub.subscribe('imgLoad',this.imgLoadListener)
  }
}



//回到顶部函数
export const backTopMixin = {
  components:{
    BackTop
  },
  data(){
    return {
      isShowBackTop:false
    }
  },
  methods:{
    // 回到顶部
    backTop(){
      this.$refs.scroll.scrollTo(0,0)
    },
    // 判断回到顶部按钮是否隐藏
    isShow(position){
      this.isShowBackTop = (-position.y) > 1000
    }
  }
}